package com.example.mobile2121606109ycg0524homework1;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;


public class AddStaffActivity extends AppCompatActivity {

    private EditText edtTxtAddName;
    private EditText edtTxtAddSkill;
    private EditText edtTxtAddSalary;
    private Button btnAddRemove;
    private Button btnAddAdd;
    private List<Staff> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_staff);
        initView();

        btnAddRemove.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        btnAddAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name = edtTxtAddName.getText().toString().trim();
                String skill = edtTxtAddSkill.getText().toString().trim();
                String salary = edtTxtAddSalary.getText().toString().trim();

                new MyDataAdapter().insert(AddStaffActivity.this,new Staff(name,skill,salary));

                list.clear();
                list.addAll(new MyDataAdapter().QueryAll(AddStaffActivity.this));

                finish();

            }
        });
    }

    private void initView() {
        edtTxtAddName = (EditText) findViewById(R.id.edtTxtAddName);
        edtTxtAddSkill = (EditText) findViewById(R.id.edtTxtAddSkill);
        edtTxtAddSalary = (EditText) findViewById(R.id.edtTxtAddSalary);
        btnAddRemove = (Button) findViewById(R.id.btnAddRemove);
        btnAddAdd = (Button) findViewById(R.id.btnAddAdd);
    }
}